<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ page import="sfmc.biz.vo.Sfmc_TB_CUSTOMER"%>
<%
String customerlist = (String)request.getAttribute("customerlist");
Sfmc_TB_CUSTOMER customerdata = (Sfmc_TB_CUSTOMER)request.getAttribute("customerdata");

if(customerlist.isEmpty() == false){
	System.out.print("\n cuList : "+customerlist+"\n");
}else{
	System.out.print("\n customerlist : null");
}
%>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=IE8" />
<meta http-equiv="Cache-Control" content="No-Cache" />
<meta http-equiv="Pragma" content="No-Cache" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>고객 등록</title>
<link rel="stylesheet" type="text/css" href="/resources/theme/metro-blue/easyui.css" />
<link rel="stylesheet" type="text/css" href="/resources/theme/icon.css" />
<link rel="stylesheet" type="text/css" href="/resources/css/ui_custom.css" />
<link rel="stylesheet" type="text/css" href="/resources/css/design.css" />
<link rel="stylesheet" type="text/css" href="/resources/css/form.css" />
<!--[if lt IE 9]>
	<script type="text/javascript" src="/resources/js/html5.js" /></script>
<![endif]-->
<script type="text/javascript" src="/resources/js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="/resources/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/resources/js/jquery.jclock.js"></script>
<script type="text/javascript" src="/resources/js/common.js" /></script>
<script type="text/javascript" src="/resources/js/is.validate.js" /></script>

<script type="text/javascript" language="javascript">
function getListEnter(){
	if(event.keyCode != 13){
		return false;
	}else{
		getList();
	}
}
function getList(){
	if( document.form.searchCustCode.value == "" && 
		document.form.searchCustName.value == "" && 
		document.form.searchCustPhone.value == "" && 
		document.form.searchCustBoss.value == "" && 
		document.form.searchCustAddr.value == "" ){
		alert("검색어를 입력하세요");
		return;
	}
	document.form.target = "_self";
	document.form.action="/customer_list.do";
	document.form.submit();
}

function clearData(){
	document.form.dataCustIdx.value = 0;
	document.form.dataCustCode.value = "";
	document.form.dataCustName.value = "";
	document.form.dataCustPhone.value = "";
	document.form.dataCustBoss.value = "";
	document.form.dataCustAddr.value = "";
}
function saveData(){
	if(validate()){
		document.form.target = "behindFrame";
		document.form.action="/customer_save.do";
		document.form.submit();
	}
}
function deleteData(){
	if(confirm("["+document.form.dataCustName.value + "]을(를) 삭제하시겠습니까?")){
		document.form.target = "behindFrame";
		document.form.action="/customer_delete.do";
		document.form.submit();	
	}
}

function reload(returnVal, type){
	
	switch(type){
	case "C": 
		alert("저장되었습니다.");
		break;
	case "U": 
		alert("수정되었습니다.");
		break;
	case "D": 
		alert("삭제되었습니다.");
		break;
	}

	document.form.target = "_self";
	document.form.action="/customer_list.do";
	document.form.submit();	
}

function validate(){
	
	var form = document.form;
	
	if(!isValideBytes(form.dataCustCode, "고객코드")){
		return false;
	}
	if(!isValideBytes(form.dataCustName, "업체명")){
		return false;
	}
	if(!isValideBytes(form.dataCustPhone, "전화번호")){
		return false;
	}
	if(!isValideBytes(form.dataCustBoss, "대표자")){
		return false;
	}
	if(!isValideBytes(form.dataCustAddr, "주소")){
		return false;
	}
	
	return true;
}
</script>
</head>
	
<body class="pop easyui-layout">
<form method="POST" name="form">
<iframe id="behindFrame" name="behindFrame"></iframe>
<input type="hidden" name="searchCustIdx" value="<%=customerdata.getSearchCustIdx()%>"/>
<input type="hidden" name="dataCustIdx" value="0"/>
	<div data-options="region:'center',border:false,iconCls:'icon-head02',title:'고객 등록'">	
	
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center',border:false">
				<div class="easyui-panel bb0" data-options="border:false,fit:true">
					<table id="grid_custom" class="easyui-datagrid"></table>
							
					<div id="tb_custom" class="datagrid-toolbar wrap_tbl_toolbar">	
						<table class="tbl_inner">	
							<colgroup>
								<col width="55px">
								<col width="120px">
								<col width="45px">
								<col width="200px">
								<col width="60px">
								<col width="120px">
							</colgroup>
							<tr>
								<th>고객코드</th>
								<td class="formText"><input type="text" name="searchCustCode" value="<%=customerdata.getSearchCustCode()%>" onKeyPress="getListEnter();"/></td>
								<th>업체명</th>
								<td class="formText"><input type="text" name="searchCustName" value="<%=customerdata.getSearchCustName()%>" onKeyPress="getListEnter();"/></td>
								<th>전화번호</th>
								<td class="formText"><input type="text" name="searchCustPhone" value="<%=customerdata.getSearchCustPhone()%>" onKeyPress="getListEnter();"/></td>
							</tr>
							<tr>
								<th>대표자</th>
								<td class="formText"><input type="text" name="searchCustBoss" value="<%=customerdata.getSearchCustBoss()%>" onKeyPress="getListEnter();"/></td>
								<th>주소</th>
								<td colspan="3" class="formText"><input type="text" name="searchCustAddr" value="<%=customerdata.getSearchCustAddr()%>" onKeyPress="getListEnter();"/></td>
								<td><a href="javascript:getList();" class="easyui-linkbutton" data-options="iconCls:'icon-search'">조회</a></td>
							</tr>
						</table>
					</div>
				</div>
			</div>
			<div data-options="region:'south',border:false">
				<div class="easyui-panel combobox-item-selected padding5" data-options="fit:true" style="height:110px;overflow:hidden">
					<div class="wrap_tbl_inner">	
						<table class="tbl_inner">	
							<colgroup>
								<col width="55px">
								<col width="120px">
								<col width="45px">
								<col>
								<col width="60px">
								<col width="120px">
							</colgroup>
							<tr>
								<th>고객코드</th>
								<td class="formText"><input type="text" name="dataCustCode" value="" MAXBYTE="10"></td>
								<th>업체명</th>
								<td class="formText"><input type="text" name="dataCustName" value="" MAXBYTE="50"></td>
								<th>전화번호</th>
								<td class="formText"><input type="text" name="dataCustPhone" value="" MAXBYTE="20"></td>
							</tr>
							<tr>
								<th>대표자</th>
								<td class="formText"><input type="text" name="dataCustBoss" value="" MAXBYTE="20"></td>
								<th>주소</th>
								<td colspan="3" class="formText"><input type="text" name="dataCustAddr" value="" MAXBYTE="100"></td>
							</tr>
						</table>						
					</div>
					<div class="btn_area">
						<a href="javascript:clearData();" class="easyui-linkbutton">초기화</a>
						<a href="javascript:saveData();" class="easyui-linkbutton">저장</a>
						<a href="javascript:deleteData();" class="easyui-linkbutton">삭제</a>
					</div>
				</div>
			</div>
		</div>
		
	</div>

	<div data-options="region:'south',border:false" class="layout_south alignL">
		Copyright 2013 Suwon City Facilities Management Corporation. All rights reserved.
		<p class="btn_close" title="닫기" onclick="window.close()"></p>
	</div>
		
</form>
<script type="text/javascript">
//그리드
$('#grid_custom').datagrid({
	rownumbers:true,
    fitColumns: true,
    singleSelect: true,
    fit: true,
    striped: true,
    toolbar:'#tb_custom',
    //pagination: true,
    nowrap: true,
    data:<%=customerlist%>,
    columns:[[
        {field:'custIdx',fixed:true,width:20,checkbox:true},
      	{field:'custCode',title:'고객코드',fixed:true,width:80,align:'center'},
      	{field:'custName',title:'업체명',fixed:true,width:120},
      	{field:'custPhone',title:'전화번호',fixed:true,width:90,align:'center'},
      	{field:'custBoss',title:'대표자',fixed:true,width:70,align:'center'},
      	{field:'custAddr',title:'주소',width:200,formatter:viewTitle}
    ]]
});
function viewTitle(val,rec){
	return '<span title="'+val+'">'+val+'</span>';
}

$('#grid_custom').datagrid({
	onClickRow:function(){
		var row = $('#grid_custom').datagrid('getSelected');
		if (row){
			document.form.dataCustIdx.value = row.custIdx;
			document.form.dataCustCode.value = row.custCode;
			document.form.dataCustName.value = row.custName;
			document.form.dataCustPhone.value = row.custPhone;
			document.form.dataCustBoss.value = row.custBoss;
			document.form.dataCustAddr.value = row.custAddr;
		}
	}
}); 
</script>
</body>

</html>